package com.bw.zhuangao5___day002.UI.Login;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * create by ertu
 * create on 2021/9/13
 * description
 */
public class LoginOkhttp {

    public static LoginOkhttp loginOkhttp;

    public static Retrofit retrofit;

    public static LoginOkhttp getLoginOkhttp() {
        if (loginOkhttp==null) {
            synchronized (LoginOkhttp.class) {
                if (loginOkhttp==null){
                    loginOkhttp = new LoginOkhttp();
                }
            }
        }
        return loginOkhttp;
    }

    public Retrofit getRetrofits(String upl) {
        if (retrofit==null) {
            synchronized (Retrofit.class) {
                if (retrofit==null) {
                    retrofit = new Retrofit.Builder().baseUrl(upl)
                            .client(new OkHttpClient.Builder()
                                    .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                                    .build())
                            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                            .addConverterFactory(GsonConverterFactory.create())
                            .build();
                }
            }
        }
        return retrofit;
    }
}
